package com.slipper.bpmn.dealer.support;

import com.slipper.constants.FlowConstants;
import com.slipper.system.flow.service.FlowInstNodeService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;
import com.slipper.bpmn.vo.BpmnVO;
import com.slipper.system.flow.bo.FlowInstBO;
import com.slipper.system.flow.bo.FlowInstNodeBO;
import com.slipper.system.flow.bo.FlowNodeBO;
import com.slipper.bpmn.dealer.INodeDealer;

/**
 * 开始节点处理器
 */
@Component
public class StartNodeDealer implements INodeDealer {
    @Resource
    private FlowInstNodeService flowInstNodeService;

    @Override
    public String[] getTypes() {
        return new String[] { "01" };
    }
    
    @Override
    public FlowInstNodeBO doDeal(
            int dealCnt,
            boolean finished,
            FlowNodeBO flowNode,
            FlowInstBO flowInst,
            FlowInstNodeBO preInstNode,
            FlowInstNodeBO currInstNode,
            BpmnVO vo) {
        this.checkDealCntAssert(dealCnt);

        FlowInstNodeBO flowInstNode = new FlowInstNodeBO();
        flowInstNode.setInstId(flowInst.getId());
        flowInstNode.setLineId(flowNode.getInLineId());
        flowInstNode.setCurrFlowNodeId(flowNode.getId());
        flowInstNode.setDealManId(vo.getCurrEmpId());
        flowInstNode.setDealOrgId(vo.getCurrOrgId());
        flowInstNode.setStartTime(System.currentTimeMillis());
        flowInstNode.setEndTime(System.currentTimeMillis());
        flowInstNode.setUpdateTime(System.currentTimeMillis());
        flowInstNode.setCreateTime(System.currentTimeMillis());
        flowInstNode.setDealStatus(FlowConstants.FlowInstNode.DEAL_STATUS_FINISHED);
        this.flowInstNodeService.save(flowInstNode);

        return flowInstNode;
    }
}
